#include "SpecialOrder.h"
#include "validation/valid.h"

SpecialOrder::SpecialOrder(){
                             instructions=NULL;
}                 
SpecialOrder::SpecialOrder(const ISBN& isbn, int o, int d, const char* instr):Order(isbn,o,d){
                              int l=strlen(instr);
                              instructions=new char[l+1];
                              strcpy(instructions,instr);   
}
SpecialOrder::SpecialOrder(const SpecialOrder& source):Order(source){
                              int l=strlen(source.instructions);
                              instructions=new char[l+1];   
                              strcpy(instructions,source.instructions);
}
void SpecialOrder::toStr(char* str) const{
     Order::toStr(str);
     strcat(str,instructions);
}
int SpecialOrder::sizeOfStr() const{
    char tmp[100];
    this->toStr(tmp);
    return strlen(tmp);
}

int SpecialOrder::augment(istream& is){
    cout<<"Quantity (0 to quit)  : ";
	int o;
    inputInt(o,0);
	if (!strcmp(instructions,"")) 
	{
		cout<<"Instructions : ";
     	inputString(instructions,INT_MAX-3);
	}
	return Order::augment(o);
}
void SpecialOrder::display(ostream& os) const{
    Order::display(os);
	os<<" "<<instructions;
}
SpecialOrder& SpecialOrder::operator=(const SpecialOrder& source){
    if(this!=&source)
    {
                     Order *tmp1=this;
                     const Order *tmp2=&source;
                     (*tmp1)=(*tmp2);
                     int l=strlen(source.instructions);
                     instructions=new char[l+1];   
                     strcpy(instructions,source.instructions);
    }
                               
}
SpecialOrder::~SpecialOrder(){
                              if (instructions!=NULL) delete[] instructions;
}

